package weaver.ihg.servlet;

import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.integration.util.JSONUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@WebServlet("/getHotelInformation")
public class HotelWebServerlt extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
        this.doGet(req, res);
    }
    //根据酒店id 值找到所有的酒店偏好的值创建任务下拉框值，基本信息，任务内容,自动发送，
    public Map<String, Object> getuf_phszList(List<String> idList) {
        Map<String, Object> addMap = new HashMap<>();
        String join = String.join(",", idList);
        RecordSet recordSet = new RecordSet();
        String sql = "select * from uf_phsz where hotelcode in (" + join + ")";
        BaseBean baseBean=new BaseBean();
        baseBean.writeLog("sql===>"+sql);
        recordSet.execute(sql);
        while (recordSet.next()) {
            Map<String, Object> paramsMap = new HashMap<>();
            paramsMap.put("jcjrw", recordSet.getInt("jcjrw"));//仅创建任务 Check框值
            paramsMap.put("cjrw", recordSet.getInt("cjrw"));//创建任务改成仅创建任务的 Check框值
            paramsMap.put("jbxx", recordSet.getInt("jbxx"));//基本信息 Check框值
            paramsMap.put("rwnr", recordSet.getInt("rwnr"));//任务内容 Check框值
            paramsMap.put("zdfs", recordSet.getInt("zdfs"));//自动发送 Check框值
            paramsMap.put("id", recordSet.getInt("id"));
            addMap.put(recordSet.getInt("id") + "", paramsMap);
        }
        baseBean.writeLog("getuf_phszList===>addMap===>"+ JSONUtil.toJSONString(addMap));
        return addMap;
    }
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
        this.doPost(req, res);
    }

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
        res.setContentType("text/html;charset=utf-8");
       String hotoleStr=req.getParameter("hotoleStr");
        BaseBean baseBean=new BaseBean();
        baseBean.writeLog("hotoleStr===>"+hotoleStr);
        Map<String, Object> stringObjectMap = getuf_phszList(Arrays.asList(hotoleStr.split(",")));
        res.getWriter().write(JSONUtil.toJSONString(stringObjectMap));

    }
}
